<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Add an authorized publickey</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.ssh2-poll.html">« ssh2_poll</a></li>
      <li style="float: right;"><a href="function.ssh2-publickey-init.html">ssh2_publickey_init »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.ssh2.html">SSH2 函数</a></li>
    <li>Add an authorized publickey</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.ssh2-publickey-add" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ssh2_publickey_add</h1>
  <p class="verinfo">(PECL ssh2 &gt;= 0.10)</p><p class="refpurpose"><span class="refname">ssh2_publickey_add</span> &mdash; <span class="dc-title">
   Add an authorized publickey
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.ssh2-publickey-add-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ssh2_publickey_add</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">resource</span> <code class="parameter">$pkey</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$algoname</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$blob</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">bool</span> <code class="parameter">$overwrite</code><span class="initializer"> = <strong><code>false</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">array</span> <code class="parameter">$attributes</code><span class="initializer"> = ?</span></span><br>): <span class="type">bool</span></div>


  <blockquote class="note"><p><strong class="note">注意</strong>: <span class="simpara">公钥子系统用于管理服务器到<em class="emphasis">已</em>被认证的客户端的公钥。要用公钥认证方法来认证远程系统，应使用
<span class="function"><a href="function.ssh2-auth-pubkey-file.html" class="function">ssh2_auth_pubkey_file()</a></span> 函数。</span></p></blockquote>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.ssh2-publickey-add-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">pkey</code></dt>

     <dd>

      <p class="para">
       Publickey Subsystem resource created by <span class="function"><a href="function.ssh2-publickey-init.html" class="function">ssh2_publickey_init()</a></span>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">algoname</code></dt>

     <dd>

      <p class="para">
       Publickey algorithm (e.g.): ssh-dss, ssh-rsa
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">blob</code></dt>

     <dd>

      <p class="para">
       Publickey blob as raw binary data
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">overwrite</code></dt>

     <dd>

      <p class="para">
       If the specified key already exists, should it be overwritten?
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">attributes</code></dt>

     <dd>

      <p class="para">
       Associative array of attributes to assign to this public key.
       Refer to ietf-secsh-publickey-subsystem for a list of supported attributes.
       To mark an attribute as mandatory, precede its name with an asterisk.
       If the server is unable to support an attribute marked mandatory,
       it will abort the add process.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.ssh2-publickey-add-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.ssh2-publickey-add-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4520">
    <p><strong>示例 #1 Adding a publickey with <span class="function"><strong>ssh2_publickey_add()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$ssh2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ssh2_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'shell.example.com'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">22</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">ssh2_auth_password</span><span style="color: #007700">(</span><span style="color: #0000BB">$ssh2</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'jdoe'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'password'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$pkey&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ssh2_publickey_init</span><span style="color: #007700">(</span><span style="color: #0000BB">$ssh2</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$keyblob&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">base64_decode</span><span style="color: #007700">(</span><span style="color: #DD0000">'<br />AAAAB3NzaC1yc2EAAAABIwAAAIEA5HVt6VqSGd5PTrLRdjNONxXH1tVFGn0<br />Bd26BF0aCP9qyJRlvdJ3j4WBeX4ZmrveGrjMgkseSYc4xZ26sDHwfL351xj<br />zaLpipu\BGRrw17mWVBhuCExo476ri5tQFzbTc54VEHYckxQ16CjSTibI5X<br />69GmnYC9PNqEYq/1TP+HF10='</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">ssh2_publickey_add</span><span style="color: #007700">(</span><span style="color: #0000BB">$pkey</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'ssh-rsa'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$keyblob</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">'comment'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"John's&nbsp;Key"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.ssh2-publickey-add-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.ssh2-publickey-init.html" class="function" rel="rdfs-seeAlso">ssh2_publickey_init()</a> - Initialize Publickey subsystem</span></li>
    <li class="member"><span class="function"><a href="function.ssh2-publickey-remove.html" class="function" rel="rdfs-seeAlso">ssh2_publickey_remove()</a> - Remove an authorized publickey</span></li>
    <li class="member"><span class="function"><a href="function.ssh2-publickey-list.html" class="function" rel="rdfs-seeAlso">ssh2_publickey_list()</a> - List currently authorized publickeys</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>